<!--
 * @Author: ylyu
 * @Date: 2024-02-22 20:20:49
 * @LastEditors: ylyu
 * @LastEditTime: 2024-02-23 20:49:26
 * @Description: 
-->
<script setup>
import { ref, inject } from 'vue'
import useWebsiteStore from '@/store/websiteStore'
const { isShow, setIsShow } = inject('dialog-visible')
const url = ref('https://www.baidu.com')
const isClickSubmit = ref(false)
const websiteStore = useWebsiteStore()

// 添加url，传给主进程
const addUrl = async () => {
  isClickSubmit.value = true
  const result = await myApi.sendUrl(url.value)
  websiteStore.add(result)
  isClickSubmit.value = false
  setIsShow(false)
}
</script>

<template>
  <div class="dialog-wrapper" v-if="isShow">
    <div class="content">
      <div class="input">
        <input
          v-model="url"
          type="text"
          placeholder="请输入网址..."
          :disabled="isClickSubmit"
        />
      </div>
      <div class="btns">
        <button @click="addUrl" :disabled="isClickSubmit">添加</button>
        <button @click="setIsShow(false)" :disabled="isClickSubmit">
          取消
        </button>
      </div>
    </div>
  </div>
</template>

<style scoped lang="css">
.dialog-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
}
.content {
  width: 100%;
  padding: 0 20px;
}
.input input {
  height: 30px;
  width: 100%;
  outline: none;
  margin-bottom: 10px;
  font-size: 12px;
}
.btns button {
  height: 30px;
  margin-right: 10px;
  font-size: 12px;
  padding: 0 20px;
}
</style>
